package com.bolt.auth.security.admin.biz;

import com.bolt.auth.security.common.annotation.EnableClientResourceServer;
import com.bolt.auth.security.common.feign.GolbalFeignConfig;
import com.bolt.support.sqlconfig.builder.SqlTemplateFactory;
import com.bolt.support.spring.jpa.repository.ExtBasicJpaRepositoryImpl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter;
import org.springframework.transaction.annotation.EnableTransactionManagement;

import java.io.IOException;

@EnableClientResourceServer
@EnableDiscoveryClient
@SpringBootApplication(scanBasePackages = {"com.bolt"})
@EnableFeignClients(defaultConfiguration = GolbalFeignConfig.class,basePackages="com.bolt.auth.admin.api.feign")
@EnableTransactionManagement
@EntityScan({"com.bolt.**.entity"})
@EnableJpaRepositories(basePackages = {"com.bolt.auth.security.admin.biz.**.repository"}, repositoryBaseClass = ExtBasicJpaRepositoryImpl.class)
public class BoltAdminApplication {

    public static void main(String[] args) {
        SpringApplication.run(BoltAdminApplication.class, args);
    }


    @Bean
    public SqlTemplateFactory createSqlTemplateBuilder() throws IOException {
        SqlTemplateFactory builder = new SqlTemplateFactory();
        builder.setSqlMapperLocations(
                new PathMatchingResourcePatternResolver().getResources("classpath:sqlconfig/sqlconfig*.xml"));
        return builder;
    }


    @Bean
    public OpenEntityManagerInViewFilter openEntityManagerInViewFilter() {
        return new OpenEntityManagerInViewFilter();
    }
}

 